<?php

class Mod_Index extends CI_Model
{
	public function getBorrowDeadline($date = 0)
	{
		$this->db->select('br.'.field('id').', br.'.field('return').', br.'.field('deadline').', br.'.field('userId'))
				->select('u.'.field('fullname'))
				->from(table('borrow').' br')
				->join(table('user').' u', 'u.'.field('id').'=br.'.field('userId'))
				->where('DATE_FORMAT(br.'.field('deadline').', "%Y-%m-%d") = ', 'DATE_FORMAT(ADDDATE(NOW(), '.$date.'), "%Y-%m-%d")', FALSE);
				
		$roleId = $this->session->userdata('userRole');
		$userId = $this->session->userdata('userId');
		
		if($roleId == 3)
		{
			$this->db->where('br.'.field('userId'), $userId);	
		}
		
		return $this->db->get();
	}
}